import http from "@/utils/request";
import { type IRes } from "@/interFace/index";


interface IPackageData extends IRes {
  data: IgetPackageList[]
}


export interface IgetPackageList {
    id: number;
    tokensTitle: string; //充值标题
    detail: null;
    price: number;   //充值金额
    amount: number; //充值量
    stock: number;
    status: number;  // 状态.1-在售 2-下架 3-删除
    createTime: string;
    updateTime: string
}
//充值套餐查询
export const getPackageList = ()=>{
  return http.get<IPackageData>("/xlx-sso/account/getpackage")
}


//支付接口
export interface IaliPay extends IRes{
  data:{
    codeUrl:string;
    orderNo:string
  }
}
// 支付宝
export const aliPay = (tokensPriceId:number|string)=>{
  return http.get<IaliPay>("/xlx-sso/alipay/scanPay?tokensPriceId="+tokensPriceId)
}

// 微信
export const wxPay = (tokensPriceId:number|string)=>{
  return http.get<IaliPay>("/xlx-sso/wxpay/native?tokensPriceId="+tokensPriceId)
}
// interface IcheckOuder extends IRes{
//   data:{
//     orderNo: string;//支付单号
//     userId: number;
//     payment: number;
//     paymentType: number;
//     tokensPriceId: number;
//     status: number; //  订单状态:0-已取消-10-未付款，20-已付款 30-交易关闭
//     paymentTime: string;
//     endTime: string;
//     closeTime: null;
//     createTime: string;
//     updateTime: string;
//     wxCodeUrl: string;
//   }
// }
// 查询订单
interface IcheckOuder extends IRes{
  data:{
    orderNo: number;//支付单号
    userId: number;
    payment: number;
    paymentType: number;
    tokensPriceId: number;
    status: number; //  订单状态:0-已取消-10-未付款，20-已付款 30-交易关闭
    paymentTime: string;
    endTime: string;
    closeTime: null;
    createTime: string;
    updateTime: string;
    wxCodeUrl: string;//wxpay/bizpayurl?pr=eiCxmVYz3
  }
}
export const checkOuder = (orderNo: string)=>{
  return http.get<IcheckOuder>("/xlx-sso/tokensOrder/get?orderNo=" + orderNo)
}

interface IAccountQuota extends IRes{
  data: {
    created: string;
    updated: string;
    totalQuota: number;  // 总额度
    usedQuota: number;  //已使用额度
    currentBalance: number//当前余额
  }
}
//用户账号总额度查询

export const getAccountQuota  = ()=>{
  return http.get<IAccountQuota>("/xlx-sso/account/getAccountQuota")
}


export interface IAccountItem {
  id:number;
  updated: string;
  created: string;// 创建时间
  serialNumber: string; //流水号
  consumption: number;//消耗量
  remarks: string; //备注
  type: number;//类型0充值 1消耗
}

interface IAccountList extends IRes {
  data: {
    id: number;
    counts: number; //总条数
    pagesize: number;//每页显示数据
    pages: number; //总页数
    page: number;//第几页
    items: IAccountItem[]
  }
}
// 账户明细
export const getAccountList = (data: object) => {
  return http.get<IAccountList>('/xlx-sso/account', data)
}
